﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Seuss.EnterpriseLibrary.DataAccess
Imports Seuss.EnterpriseLibrary.BusinessLogic
Imports System.Web
Imports System.Data

Partial Public Class Consulta_Do_CursoAsig_Anun
    Inherits System.Web.UI.Page
    Dim nCurGruCodigo As String
    Dim cdoccodigo As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.QueryString("nCurGruCodigo") Is Nothing Or Request.QueryString("nCurGruCodigo") Is String.Empty Then
            If Session("nCurGruCodigo") Is Nothing Or Session("nCurGruCodigo") Is String.Empty Then
                Response.Redirect("DO_ListaCursAsig.aspx")
            Else
                nCurGruCodigo = Session("nCurGruCodigo")
            End If
        Else
            Session("nCurGruCodigo") = Request.QueryString("nCurGruCodigo")
            nCurGruCodigo = Request.QueryString("nCurGruCodigo")
        End If
        Response.Expires = -1
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("cache-control", "private")
        Response.CacheControl = "no-cache"
        lnkRegresar_3.HRef = "./Do_CursoAsignado.aspx?nCurGruCodigo=" + nCurGruCodigo
        lnkRegresar_4.HRef = "./Do_CursoAsignado.aspx?nCurGruCodigo=" + nCurGruCodigo

        If Not (Request.QueryString("eliminar") Is Nothing Or Request.QueryString("eliminar") Is String.Empty) Then
            If Not (Request.QueryString("cdoccodigo") Is Nothing Or Request.QueryString("cdoccodigo") Is String.Empty) Then
                If Request.QueryString("eliminar") = "si" Then
                    cdoccodigo = Request.QueryString("cdoccodigo")
                    Using ObjPool As New PoolDbCommand()
                        Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
                        ObjPool.AddDbCommand(Objgrupo.Del_Anuncio(cdoccodigo), PoolDbCommand.PoolDbCommandResultType.NonQuery)
                        If ObjPool.Pooling() Then
                            Using Seguridad As New BLL_Administracion
                                Seguridad.Set_Transaccion_Insert(Nothing, 100407, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Eliminar Anuncio", "/cDocCodigo|" + cdoccodigo))
                            End Using
                        End If
                    End Using
                End If
            End If
        End If

        If Not Page.IsPostBack Then
            CargarAnuncios()
            Using Seguridad As New BLL_Administracion
                Seguridad.Set_Transaccion_Insert(Nothing, 100401, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Consulta Pagina Movil", "/Pagina|" + My.Request.Url.Segments(My.Request.Url.Segments.Length - 1).ToString))
            End Using
        End If
    End Sub

    Private Sub CargarAnuncios()

        Dim DivAnuncios As New StringBuilder

        Dim ldrItem As New List(Of IDataReader)
        Using ObjPool As New PoolDbCommand()
            Dim ObjData As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjData.Get_Anuncio_By_nCurGruCodigo(nCurGruCodigo), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldrItem, True)
        End Using

        While ldrItem(0).Read
            DivAnuncios.Append("<ul><li>")
            DivAnuncios.Append("<p><strong>" & ldrItem(0).Item("cDocObserv").ToString & "</strong></p><p style=""white-space:normal; text-align:justify;"">" & ldrItem(0).Item("tDocConContenido").ToString & "</p>")
            DivAnuncios.Append("<p class=""ui-li-aside"">" & ldrItem(0).Item("Dia").ToString & " de " & ldrItem(0).Item("Mes").ToString & "</p>")
            DivAnuncios.Append("<p>De:  <strong>" & ldrItem(0).Item("ALIAS").ToString & "</strong><a style='font-size:10px; text-align:right;' href='Do_CursoAsig_Anun.aspx?eliminar=si&cdoccodigo=" & ldrItem(0).Item("cDocCodigo").ToString & "'>Eliminar</a></p>")
            DivAnuncios.Append("</li></ul>")
        End While
        lblcontenido.Text = DivAnuncios.ToString
        ldrItem(0).Close()
        ldrItem = Nothing

    End Sub

    Protected Sub btnNuevoAnuncio_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNuevoAnuncio.Click
        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Ins_Anuncio(txtTitulo.Text, IdentityUser.UserCode, nCurGruCodigo, txtContenido.Text), PoolDbCommand.PoolDbCommandResultType.NonQuery)
            If ObjPool.Pooling() Then
                Using Seguridad As New BLL_Administracion
                    Seguridad.Set_Transaccion_Insert(Nothing, 100406, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Registrar Anuncio", "/nCurGruCodigo|" + nCurGruCodigo + "/Titulo|" + Trim(txtTitulo.Text)))
                End Using
                txtTitulo.Text = ""
                txtContenido.Text = ""
            End If
        End Using
        Response.Redirect("DO_CursoAsig_Anun.aspx?nCurGruCodigo=" + nCurGruCodigo)
    End Sub

End Class